using System.Collections.Generic;
using System.IO;
using System.Text;
using Rhino.Etl.Core;
using Rhino.Etl.Core.Operations;

namespace EtlDemo.Rhino
{
    public class RowVisualizer : AbstractOperation
    {
        readonly TextWriter _writer;

        public RowVisualizer(TextWriter writer)
        {
            _writer = writer;
        }

        public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
        {
            foreach (var row in rows)
            {
                var sb = new StringBuilder();
                foreach (var column in row.Columns)
                {
                    sb.AppendFormat("[{0}]: {1} | ", column, row[column]);
                }
                _writer.WriteLine(sb.ToString().TrimEnd(' ','|'));
                yield return row;
            }
        }
    }
}